package com.example.demo.exception;

import com.example.demo.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



@RestControllerAdvice  //统一处理
public class GlobalExceptionHandlerAdvice {
    Logger log = LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);
    @ExceptionHandler({Exception.class}) //什么异常的统一处理
    public Result handleException(Exception e, HttpServletRequest request, HttpServletResponse response)
    {
        //记录日志
        log.error("异常信息："+e.getMessage());


        return new Result(500,e.getMessage(),null);
    }
}
